using Com.Core.Module.Entities;
using Com.Core.Module.Filters;
using Com.Modules.SimplifyModule.Dtos.Example;
using Com.Modules.SimplifyModule.Services;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using XiheNet;

namespace Com.Modules.SimplifyModule.Controllers;

/// <summary>
/// 示例控制器框架，请根据实际业务需求修改
/// </summary>
[Route("api/simplify/Example")]
[EnableCors("myCors")]
[ApiController]
public class ExampleController : ControllerBase
{
    private readonly ILogger<ExampleController> _logger;
    private readonly ExampleService _exampleServ;
    public ExampleController(
        ILogger<ExampleController> logger
        , ExampleService exampleServ
    ) {
        _logger = logger;
        _exampleServ = exampleServ;
    }


    /// <summary>
    /// 获取树型列表 - GET /api/simplify/Example/tree
    /// </summary>
    /// <returns>树型列表响应结果</returns>
    [HttpGet("tree")]
    [JwtAuth("Admin")]
    public async Task<XResponse<GetExampleTreeResponse>> GetTree() {
        XResponse<GetExampleTreeResponse> relt = new XResponse<GetExampleTreeResponse>();

        // // 从HttpContext中获取用户信息
        // if (HttpContext.Items["CurrentAdmin"] is not AdminDto admin) {
        //     relt.RespHead.Code = "1000";
        //     relt.RespHead.Message = "用户会话信息丢失";
        //     return relt;
        // }

        // 参数格式有效性校验

        // Tran事务处理并返回结果

        return relt;
    }


    /// <summary>
    /// 保存示例 - POST /api/simplify/Example
    /// </summary>
    /// <param name="req">保存供应商分类请求参数</param>
    /// <returns>保存供应商分类响应结果</returns>
    [HttpPost()]
    [JwtAuth("Admin")]
    public async Task<XResponse<IdResponse>> Save(
        [FromBody] SaveExampleRequest req
    ) {
        XResponse<IdResponse> relt = new XResponse<IdResponse>();

        // // 从HttpContext中获取用户信息
        // if (HttpContext.Items["CurrentAdmin"] is not AdminDto admin) {
        //     relt.RespHead.Code = "1000";
        //     relt.RespHead.Message = "用户会话信息丢失";
        //     return relt;
        // }

        // 参数格式有效性校验

        // Tran事务处理并返回结果

        return relt;
    }


    /// <summary>
    /// 删除示例 - POST /api/simplify/Example/{id}
    /// </summary>
    /// <param name="id">示例ID</param>
    /// <returns>树型列表响应结果</returns>
    [HttpPost("{id}")]
    [JwtAuth("Admin")]
    public async Task<XResponse<EmptyBody>> Delete(
        [FromRoute] int id
    ) {
        XResponse<EmptyBody> relt = new XResponse<EmptyBody>();

        // // 从HttpContext中获取用户信息
        // if (HttpContext.Items["CurrentAdmin"] is not AdminDto admin) {
        //     relt.RespHead.Code = "1000";
        //     relt.RespHead.Message = "用户会话信息丢失";
        //     return relt;
        // }

        // 参数格式有效性校验

        // Tran事务处理并返回结果

        return relt;
    }


}

